<template>
  <van-search v-model="value" placeholder="请输入搜索关键词" />
  <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" >
    <van-swipe-item v-for="image in images" :key="image">
      <van-image
          width="100%"
          height="10rem"
          :src="image"
      />
    </van-swipe-item>
  </van-swipe>
  <van-cell title="最新资讯" icon="fire-o"  is-link to="article-list">
    <template #right-icon>
      <van-icon name="arrow" />
    </template>
  </van-cell>
  <div class="van-hairline--bottom" v-for="item in articles" :key="item">
    <van-cell center :title="item.title" :to="'article?id='+item.id"/>
  </div>
  <van-divider />
  <van-cell title="最新发布" icon="shop-o"  is-link to="goods">
    <template #right-icon>
      <van-icon name="arrow" />
    </template>
  </van-cell>
  <div v-for="item in goods" :key="item.id" v-bind="item.id">
    <van-card
        :id="item.id"
        num="1"
        :price="item.price"
        :title="item.name"
        :thumb="'http://local.bs.com/storage/'+item.image"
        @click="detail(item.id)"
    />
  </div>
</template>

<script>
// @ is an alias to /src

import {getGoodsList} from "@/api/goods";
import {articleList} from "@/api/article"
export default {
  name: 'Home',
  data() {
    return {
      images: [
        'http://local.bs.com/storage/goods/big9001.jpg',
        'http://local.bs.com/storage/goods/big5001.jpg',
        'http://local.bs.com/storage/goods/big10000.jpg',
        'http://local.bs.com/storage/goods/big9000.jpg',
      ],
      goods: {},
      articles:{}
    };
  },
  created(){
    let that = this;
    getGoodsList().then((res)=>{
      that.goods = res.data.data
    })
    articleList(1,5).then((res)=>{
      that.articles = res.data.data
    })
  },
  methods:{
    detail(id){
      this.$router.push('detail?id='+id)
    }
  }
}
</script>

<style>
  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    text-align: center;
  }
  .van-card{
    border:1px solid #fff
  }
</style>
